from contextlib import asynccontextmanager

from fastapi import FastAPI
from logger import log


@asynccontextmanager
async def lifespan(app: FastAPI):
    """
    @app.on_event("startup")
    @app.on_event("shutdown")
     都已过时，推荐使用此方式

    :param app: FastAPI
    """
    log.info("启动前执行... app: %s" % app)
    yield
    log.info("关闭后执行...")

